package com.syt.cellphone.information.ui.main.phone

import android.app.Application
import com.syt.cellphone.information.App
import com.syt.cellphone.information.base.BaseViewModel
import com.syt.cellphone.information.data.pojo.PhoneGroup

/**
 *  @author: syt
 *  创建时间: 2020/8/24 17:09
 *  @功能   手机数据
 *  @version v1.0
 */
class PhoneViewModel(application: Application) : BaseViewModel(application) {

    fun checkGroup(groups: List<PhoneGroup>) {
        execute {
            groups.forEach { group ->
                if (group.groupId and (group.groupId - 1) != 0) {
                    var id = 1
                    val idsSum = App.db.phoneGroupDao().idsSum
                    while (id and idsSum != 0) {
                        id = id.shl(1)
                    }
                    App.db.phoneGroupDao().delete(group)
                    App.db.phoneGroupDao().insert(group.copy(groupId = id))
//                    App.db.phoneBaseDao().up
                }
            }
        }
    }

}